'use strict';
let arr=[];
function changeIntoArray(collection){
  for(let i in collection){
    if(typeof collection[i]=="object"){
      changeIntoArray(collection[i]);
    }
    else{
      arr.push(collection[i]);
    }
  }
  return arr;
}
function includes(collection,ch){
  for(let item of collection){
    if(ch===item){
      return true;
    }
  }
  return false;
}

function collectSameElements(collectionA,collectionB){
  let result=[];
  collectionB=collectionB.value;
  collectionA=changeIntoArray(collectionA);
  for(let item of collectionA ){
    if(includes(collectionB,item)){
      result.push(item);
      console.log(result);
    }
  }
  console.log(result);
  return result;
}
module.exports =  collectSameElements;

